package com.snail.billing.session;

import org.json.JSONException;
import org.json.JSONObject;

import com.snail.billing.DataCache;
import com.snail.billing.json.JsonBase;
import com.snail.billing.net.BillingSecurity;
import com.snail.billing.net.BillingTreeArrayHttpSession;

public class ForgetPwdQueryEmailSession extends BillingTreeArrayHttpSession {

	public ForgetPwdQueryEmailSession(String account) {
		DataCache cache = DataCache.getInstance();
		String host = cache.importParams.hostSecurity;
		BillingSecurity security = getSecurity();
		String address = String.format("http://%s/api/%s/%s/querypassportemail", host, security.accessId, security.accessType);
		setAddress(address);
		addBillingPair("account", account);
		buildParamPair();
	}

	@Override
	public BillingSecurity getSecurity() {
		if (DataCache.getInstance().isSandbox) {
			return BillingSecurity.securitySandbox2;
		}
		return BillingSecurity.security;
	}

	public static class JsonData extends JsonBase {

		private String bindState;
		private String email;

		public JsonData(String jsonString) {
			super(jsonString);
			try {
				if (getCode() == 1) {
					JSONObject json = new JSONObject(jsonString);
					if (json.has("bindState")) {
						bindState = json.getString("bindState");
					}
					if (json.has("email")) {
						email = json.getString("email");
					}
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		public String getBindState() {
			return bindState;
		}

		public String getEmail() {
			return email;
		}

	}

}
